package com.ykqx.weather.app.util;

import java.io.File;
import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/6/21 0021
 */
public class FileSortUtil {

    public static void OrderByDate(File[] files) {

        //按时间从最新到最早排列
        Arrays.sort(files, new Comparator<File>() {
            public int compare(File f1, File f2) {
                long diff = f1.lastModified() - f2.lastModified();
                if (diff > 0)
                    return -1;
                else if (diff == 0)
                    return 0;
                else
                    return 1;
            }
        });
    }
}
